#include "funciones.h"
#include <iomanip>
#include <openssl/md5.h>
void md5imprimir(unsigned char* buffer,int size)
{
	for(int i = 0; i < size; ++i) {
        std::cout << std::hex          /* print numbers as hexadecimal */
                  << std::setw(2)      /* print two digits */
                  << std::setfill('0') /* pad with '0' */
                  << static_cast<int>(buffer[i]);
    }
    std::cout << std::endl;
}

void md5(std::string funcion,char *checksum)
{
    unsigned char buffer[16];
	MD5((unsigned char*)funcion.c_str(), funcion.size(), buffer);
	for(int i=0; i<16; i++ ){
        sprintf( &checksum[2*i], "%02x", buffer[i] );
    }
    //std::cout << buffer << std::endl;
}
void md5(byte* funcion,int largo,char *checksum)
{
	unsigned char buffer[16];
	MD5((unsigned char*)funcion, largo, buffer);
	for(int i=0; i<16; i++ ){
        sprintf( &checksum[2*i], "%02x", buffer[i] );
    }
}

void serializarInt(int socket,int a)
{
	byte b0 = a & 255;
	byte b1  = (a >> 8) & 255;
	byte b2 = (a >> 16) & 255;
	byte b3 = (a >> 24) & 255;

	
	int ja = b0 + b1 + b2 + b3;
	std::cout << std::hex << ja << std::endl;
	std::cout << b0 << b1 << b2 << b3 << std::endl;
}

void serializarFloat(int socket,float a)
{
	byte *p = (byte *)&a;
	
}

byte * serializarString(const char *str)
{
	return (byte *)str;
}
char * desserializarString(byte *str)
{
 return (char *)str;
}

// int deserializarInt(int socket)
// {
// 	int ja = b0 | b1 << 8 | b2 << 16 | b3 << 24;
// }